import 'package:flutter/material.dart';
import 'package:scan_barcode/scan_barcode.dart';

class ScanPage extends StatefulWidget {
  const ScanPage({Key? key}) : super(key: key);

  @override
  State<ScanPage> createState() => _ScanPageState();
}

class _ScanPageState extends State<ScanPage> {
  var isPop = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: BarcodeWidget(
        onHandleBarcodeList: (List<Barcode> barcode) async {
          if (isPop) {
            // Prevent multiple pop
            return;
          }
          if (barcode.isEmpty) return;
          isPop = true;
          Navigator.of(context).pop(barcode);
        },
        scanValue: ScanValue(),
      ),
    );
  }
}
